package com.example.origin.demo.design.chain;

import lombok.Data;

/**
 * 1、一个请求需要总经理=>经理=>专员来批复
 *
 * @author yutao
 * @create 2018-07-16 11:54
 **/
public class ChainDemo2 {

    public static void main(String[] args) {
        //组装责任链
        Handler2 handler1 = new GeneralManager2();
        Handler2 handler2 = new Manager2();
        Handler2 handler3 = new Commissioner2();
        handler1.setSuccessor(handler2);
        handler2.setSuccessor(handler3);
        //提交请求
        handler1.handleRequest();
    }

}



@Data
class Handler2{

    protected Handler2 successor;

    void handleRequest(){
        if (getSuccessor()==null) {
            System.out.println(this.getClass().getSimpleName()+"handle");
        }else {
            this.getSuccessor().handleRequest();
        }
    }

}
class GeneralManager2 extends Handler2{

}
class Manager2 extends Handler2{

}
class Commissioner2 extends Handler2{

}

